#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/7/16 11:13
# @Author : wl
# @File : serializer.py  # 填充项目对应的模型层

from django.db import models


class BaseMode(models.Model):
    """
    基础,models
    """

    created_at = models.DateTimeField(
        auto_now_add=True,
        verbose_name='记录创建时间',
    )

    update_at = models.DateTimeField(
        auto_now=True,
        verbose_name='记录修改时间',
    )

    class Meta:
        abstract = True


class LotteryTheme(BaseMode):
    lottery_theme_name = models.CharField(
        max_length=128,
        null=True,
        blank=True,
        verbose_name='抽奖主题名字',
    )
    is_now = models.BooleanField(
        default=False,
        blank=True,
        verbose_name='是否是这次抽奖主题'
    )
    draw_at = models.CharField(
        max_length=128,
        default=None,
        blank=True,
        verbose_name='开奖时间',
    )
    people_number = models.IntegerField(
        default=0,
        blank=True,
        verbose_name='本次主题参与人数'
    )
    contract_address = models.CharField(
        max_length=128,
        null=True,
        blank=True,
        default="",
        verbose_name='合约地址',
    )

    class Meta:
        db_table = '主题设置表'
        verbose_name = "主题设置信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.lottery_theme_name


class CollectionInfoModels(BaseMode):
    """
     用户表单记录收集表
    """

    full_name = models.CharField(
        max_length=128,
        null=True,
        blank=True,
        verbose_name='姓名',
    )

    email = models.EmailField(
        max_length=128,
        null=True,
        blank=True,
        verbose_name='邮箱地址',
    )

    telegram_username = models.CharField(
        max_length=128,
        null=True,
        blank=True,
        verbose_name='用户名',
    )

    bep_wallet_address = models.CharField(
        max_length=128,
        null=True,
        blank=True,
        verbose_name='钱包地址',
    )

    is_hook = models.BooleanField(
        default=False,
        verbose_name='是否中奖',
    )
    theme = models.ForeignKey(
        LotteryTheme,
        related_name='related_themes',
        db_constraint=False,
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        verbose_name='登录信息关联的主题奖项'
    )

    class Meta:
        db_table = 'collection_info'
        verbose_name = "用户信息收集表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.full_name